import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';
import LoginService from 'containers/login/login.service';

export default {
  //
  getAllProtocols: function (id, username) {
    return new Promise((resolve, reject) => {
      httpFetch.get(config.baseUrl + `/api/tenant/protocol/id?id=${id}&username=${username}` )
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },

  //
  getUserProtocols: function (mobile_or_email) {
    return LoginService.getPasswordRuleV2(mobile_or_email, false);
  },

  // 微信登录用户同意协议
  weChatAgreeProtocol: function () {
    //建议能用邮箱获取,就邮箱,因为手机可能被修改
    return new Promise((resolve, reject) => {
      httpFetch.post(config.baseUrl + '/api/tenant/protocol/approval')
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
}
